import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";

export type dateTemType = "datetime" | "date" | "time" | "current" | undefined;

dayjs.extend(relativeTime);
export const dateTimeFormat = (date: string): string => {
  return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
};
export const dateFormat = (date: string): string => {
  return dayjs(date).format("YYYY-MM-DD");
};
export const timeFormat = (date: string): string => {
  return dayjs(date).format("HH:mm:ss");
};
export const dateCurrentFormat = (date: string): string => {
  return dayjs().to(dayjs(date));
};
export const dateCustomFormat = (
  date: string,
  format?: dateTemType
): string => {
  switch (format) {
    case "date":
      return dateFormat(date);
    case "time":
      return timeFormat(date);
    case "current":
      return dateCurrentFormat(date);
    default:
      return dateTimeFormat(date);
  }
};
